package com.ruoyi.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ManeuveringPlatform;
import com.ruoyi.system.service.IManeuveringPlatformService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 海上机动平台Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/system/PLATFORM")
@Api(tags = "海上机动平台")
public class ManeuveringPlatformController extends BaseController
{
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    @Autowired
    private IManeuveringPlatformService maneuveringPlatformService;


    /**
     * WebSocket
     */
    @MessageMapping("/message/{to}")
//    @SendToUser("/queue/reply")
    public void handleMessage2(@DestinationVariable String to, @Payload String message) {
//    public void handleMessage2( @Payload String message) {
        System.out.println("接收到前端发送的消息: " + message);
        // 示例：将消息原样返回给发送者
        // 这里需要根据实际情况获取用户名
        Map<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("fe","问问呢进去喷雾剂屁淘金热喷漆件恶评群文件泡脚桶陪我截个屏二级品金额泡温泉金额平群文件");
        try {
            simpMessagingTemplate.convertAndSend( "/topic/"+to, stringStringHashMap);
//            simpMessagingTemplate.convertAndSend( "/topic/fe/" ,"dwad"+message);

        } catch (Exception e) {
            System.err.println("Error sending message: " + e.getMessage());
        }

    }


    /**
     * 查询海上机动平台列表
     */
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManeuveringPlatform maneuveringPlatform)
    {
        startPage();
        List<ManeuveringPlatform> list = maneuveringPlatformService.selectManeuveringPlatformList(maneuveringPlatform);
        return getDataTable(list);
    }

    /**
     * 导出海上机动平台列表
     */
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:export')")
    @Log(title = "海上机动平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManeuveringPlatform maneuveringPlatform)
    {
        List<ManeuveringPlatform> list = maneuveringPlatformService.selectManeuveringPlatformList(maneuveringPlatform);
        ExcelUtil<ManeuveringPlatform> util = new ExcelUtil<ManeuveringPlatform>(ManeuveringPlatform.class);
        util.exportExcel(response, list, "海上机动平台数据");
    }

    /**
     * 获取海上机动平台详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(maneuveringPlatformService.selectManeuveringPlatformByID(ID));
    }

    /**
     * 新增海上机动平台
     */
    @ApiOperation(value = "新增一下")
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:add')")
    @Log(title = "海上机动平台", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManeuveringPlatform maneuveringPlatform)
    {
        return toAjax(maneuveringPlatformService.insertManeuveringPlatform(maneuveringPlatform));
    }

    /**
     * 修改海上机动平台
     */
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:edit')")
    @Log(title = "海上机动平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManeuveringPlatform maneuveringPlatform)
    {
        return toAjax(maneuveringPlatformService.updateManeuveringPlatform(maneuveringPlatform));
    }

    /**
     * 删除海上机动平台
     */
    @PreAuthorize("@ss.hasPermi('system:PLATFORM:remove')")
    @Log(title = "海上机动平台", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(maneuveringPlatformService.deleteManeuveringPlatformByIDs(IDs));
    }
}
